//
//  NRWBuyCarListRectModel.m
//  NRWMall
//
//  Created by 邢毅 on 2018/6/25.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWBuyCarListRectModel.h"

@implementation NRWBuyCarListRectModel

- (void)setDataModel:(Result *)dataModel {
	
	_dataModel = dataModel;
	
	[self setupCarLicenceStr];
	[self setupCarMileageStr];
	[self setupDetailStr];
	
	self.certifylogoImageViewFrame = CGRectMake(-5, -5, 61, 17);
	self.carIconImageViewFrame = CGRectMake(16, 10, 120, 80);
	
	CGSize titleSize = [dataModel.carTitle sizeWithFont:getThemeFont(14) andMaxSize:CGSizeMake(SCREEN_WIDTH() - 26 - 9 - CGRectGetMaxX(self.carIconImageViewFrame), 40)];
	self.carTitleLabelFrame = CGRectMake(CGRectGetMaxX(self.carIconImageViewFrame) + 9, CGRectGetMinY(self.carIconImageViewFrame), titleSize.width, titleSize.height);
	
	CGSize timeSize = [dataModel.market.city.cityName sizeWithFont:getThemeFont(11) andMaxSize:CGSizeMake(100, 11)];
	self.timeLabelFrame = CGRectMake(self.carTitleLabelFrame.origin.x, CGRectGetMaxY(self.carIconImageViewFrame) - 11, timeSize.width, 11);
	
	CGSize detailSize = [self.detailStr sizeWithFont:getThemeFont(11) andMaxSize:CGSizeMake(300, 11)];
	self.detailLabelFrame = CGRectMake(self.carTitleLabelFrame.origin.x, CGRectGetMinY(self.timeLabelFrame) - 10 - 11, detailSize.width, 11);
	
	CGSize unitSize = [@"万" sizeWithFont:getBoldFont(13) andMaxSize:CGSizeMake(50, 50)];
	self.priceUnitLabelFrame = CGRectMake(SCREEN_WIDTH() - 16 - unitSize.width, CGRectGetMaxY(self.carIconImageViewFrame) - 14, unitSize.width, 14);
	
	if (dataModel.carRetailPrice == 0) {
		
		self.priceStr = @"价格面议";
		
		CGSize noPriceSize = [@"价格面议" sizeWithFont:getThemeFont(16) andMaxSize:CGSizeMake(200, 100)];
		self.priceLabelFrame = CGRectMake(SCREEN_WIDTH() - 16 - noPriceSize.width, CGRectGetMaxY(self.carIconImageViewFrame) - 15, noPriceSize.width, 15);
	} else {
		
		self.priceStr = [NSString stringWithFormat:@"%.2f", dataModel.carRetailPrice];

		CGSize priceSize = [[NSString stringWithFormat:@"%.2f", self.dataModel.carRetailPrice] sizeWithFont:getBoldFont(22) andMaxSize:CGSizeMake(100, 18)];
		self.priceLabelFrame = CGRectMake(CGRectGetMinX(self.priceUnitLabelFrame) - priceSize.width, CGRectGetMaxY(self.carIconImageViewFrame) - 18, (int)priceSize.width + 1, 18);
	}
}

- (void)setupDetailStr {
	
	self.detailStr = [NSString stringWithFormat:@"%@/%@",self.carLicenceStr, self.carMileageStr];
}

- (void)setupCarLicenceStr {
	
	if (self.dataModel.carLicenceState == 1) {
		self.carLicenceStr = [NSString stringWithFormat:@"%@",[NRWCarTurnTime timestampSwitchTime:self.dataModel.carLicenceDate andFormatter:@"yyyy年MM月"]];
	}else if (self.dataModel.carLicenceState == 2){
		self.carLicenceStr = @"未上牌";
	}else if (self.dataModel.carLicenceState == 3 ){
		self.carLicenceStr = @"新车";
	}
}

- (void)setupCarMileageStr {
	
	if (self.dataModel.carMileage <= 0) {
		self.carMileageStr = @"未输入里程";
	}else{
		if (self.dataModel.carMileage < 0.1) {
			self.carMileageStr = [NSString stringWithFormat:@"%.f公里", self.dataModel.carMileage *10000];
		}else{
			self.carMileageStr = [NSString stringWithFormat:@"%.2f万公里",self.dataModel.carMileage];
		}
	}
}

- (NSString *)carMileageStr {
	
	if (isEmptyString(_carMileageStr)) {
		return @"未输入里程";
	}
	return _carMileageStr;
}

@end
